package com.ruyuan.eshop.common.framework.validation.impl;

import com.ruyuan.eshop.common.framework.RuyuaneshopConfig;
import com.ruyuan.eshop.common.framework.exception.ServiceException;
import com.ruyuan.eshop.common.framework.exception.SystemErrorCodeV1;
import com.ruyuan.eshop.common.framework.validation.annotation.DemoSiteDisable;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 演示站点是否可以被操作切面类
 *
 * @author pwd
 * @version 1.0
 */
@Component
@Aspect
public class DemoSiteAspect {

    @Autowired
    private RuyuaneshopConfig ruyuaneshopConfig;

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Before("@annotation(demoSiteDisable)")
    public void doAfter(DemoSiteDisable demoSiteDisable) throws Exception {
        if (ruyuaneshopConfig.getIsDemoSite()) {
            logger.debug("演示站点禁止此操作");
            throw new ServiceException(SystemErrorCodeV1.NO_PERMISSION, "演示站点禁止此操作");
        }
    }

}
